function getCSRFToken() {
    var cookieValue = null;
    var name = 'csrftoken';
    var cookies = document.cookie.split(';');
    for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i].trim();
        if (cookie.substring(0, name.length + 1) === (name + '=')) {
            cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
            break;
        }
    }
    return cookieValue;
}

document.getElementById('login-btn').addEventListener('click', function () {
    var username = document.getElementById('username').value;
    var password = document.getElementById('password').value;

    var data = {
        username: username,
        password: password,
        csrfmiddlewaretoken: getCSRFToken() , // 添加CSRF令牌
    };

    $.ajax({
        type: "POST",
        url: "/login",
        data: data,
    });
});